<extend name="Public/base"/>
<block name="head">
    <link href="__PUBLIC__/plugins/bootstrap-editable/css/bootstrap-editable.css" rel="stylesheet" type="text/css" />
    <link href="__PUBLIC__/plugins/bootstrap-editable/css/custom_link.css" rel="stylesheet" type="text/css" />
</block>
<block name="body">
    <style>
        .link-lists .linkitem{
            margin: 10px 0px;
            min-height: 60px;
            border-bottom: 1px dashed  #ddd;

        }
        .link-lists .linkitem.last{
            border-bottom:none;
        }
        .link-lists .link-row{
            line-height: 60px;
        }
        .link-lists button.editable-remove{
            margin: 5px 0px;
        }

    </style>

    <?php if ($link_role != 'core'): ?>
    <style>
        .link-stytem .editable-submit ,.link-stytem .editable-removelink{display: none}
    </style>
    <?php endif; ?>
    <section class="content">

        <div class="panel panel-primary com-link-panel">
            <div class="panel-heading">
                <label>{$Think.lang.Link}</label>
                <a href="javascript:;" id="edit-button" class="pull-right" style="color: #FFFFFF" tab="edit">{$Think.lang.Edit}</a>
            </div>
            <div class="panel-body">

                <div class="link-lists">
                    <?php $count = 0; ?>
                    <volist name="linklist" id="item">
                        <div class="row linkitem link-stytem">
                            <div class="col-md-1  link-row " style="min-width: 89px">
                                <?php $row = $key; ?>
                                <label>{$key|getOptionsLabel = C('link_category')}</label>
                            </div>
                           <div class="col-md-11 link-row ">
                            <volist name="item" id="val">
                                    <?php
                                            $url = $val['url'];
                                            if ($val['title'] == 'C6 System'){
                                                $url = $c6_url;
                                            }else if ($val['title'] == 'Internal Forum'){
                                                $url = $forum_url;
                                            }else if ($val['title'] == 'ETS System'){
                                                $url = $ets_login_url;
                                            }else if ($val['title'] =='Questionnaire System'){
                                                $url = $val['url'].'?uid='.$login_code;
                                            }
                                     ?>
                                    <div class="  col-md-3 col-sm-6 col-xs-12 text-left ">
                                    <a href="{$url}" data-removelink="__URL__/removeLink/id/{$val['id']}" target="_blank" data-type="address"
                                     data-renderhome="__URL__/renderhome/id/{$val['id']}/tag/link"  data-pk="{$val['id']}"  data-title="Enter {$val['title']}" class="editable" style="cursor: pointer !important; overflow: hidden">
                                        <img src="{$val['icon']}"  style="max-width: 20px"/>
                                        <span><?php echo L($val['title']); ?></span>
                                    </a>
                                    </div>
                            </volist>
                               <?php if ($link_role == 'core'): ?>
                               <a href="" data-type="address"  data-placement="right" data-pk="" category="{$row}"  class="editable editable-click  btn btn-primary link-new " style="display: none;padding: 3px;"  >Add</a>
                                <?php endif; ?>
                           </div>
                            <?php $count++; ?>
                        </div>
                    </volist>
                      <div class="col-md-1  link-row " style="min-width: 89px">
                       		<label>{$Think.lang.Favorites}</label>
                      </div>
                    <div class="row linkitem last">
                        <div class="col-md-11 link-row ">
                          <volist name="favoriteList" id="items">
                        	<volist name="items" id="item">
                                <?php
									 $favoriteUrl = $item['favorite_url'];
                                ?>
	                         	<div class="  col-md-3 col-sm-6 col-xs-12 text-left ">
		                             <a href="{$favoriteUrl}" data-removelink="__URL__/removeFavoriteLink/id/{$item['id']}" target="_blank" data-type="address"
		                                   data-renderhome="__URL__/renderhome/id/{$item['id']}/tag/favorite"   data-pk="{$item['id']}" category = "8" data-title="Enter {$item['title']}" class="editable" style="cursor: pointer !important; overflow: hidden">
		                                   <img src="{$item['icon']}"  style="max-width: 20px"/>
		                                   <span><?php echo $item['title']; ?></span>
		                             </a>
	                         	</div>
                            </volist>
                       	  </volist>
                            <a href="" data-type="address"  data-placement="right" data-pk="" category="8" tag="favorite" class="editable editable-click  btn btn-primary link-new " style="display: none;padding: 3px;"  >Add</a>
                        </div>
                    </div>
                  
                </div>

            </div>
         </div>
    </section><!-- /.content -->

</block>
<block name="script">
    <script src="__PUBLIC__/plugins/bootstrap-editable/js/bootstrap-editable.js" type="text/javascript"></script>
    <script src="__PUBLIC__/plugins/bootstrap-editable/js/custom_link.js" type="text/javascript"></script>
    <script type="text/javascript">

        $('#edit-button').click(function() {
            $('.com-link-panel .editable').editable('toggleDisabled');
            $('.com-link-panel .link-new').toggle();
            $(this).attr('tab') == 'edit'?$(this).text('<?php echo L("Esc");?>').attr('tab','esc'):$(this).text('<?php echo L("Edit");?>').attr('tab','edit');
        });
        $(function(){

            $('.com-link-panel .editable').each(function(){
                var then = $(this);
                var furl;
                if (then.attr('category') == '8' ){
                	furl = '__URL__/saveFavorite';
                } else {
                	furl = '__URL__/ajaxChangeLink';
                }
                $(this).editable({
                        url: furl,
                        title: 'Enter username',
                        params: function(params) {
                            params.category_id = then.attr('category');
                            return params;
                        },
                        value:  {
                            title: then.find('span').html(),
                            link: then.attr('href')
                        },
                        validate: function(value) {
                            if(value.title == '') return 'title is required!';
                            if(value.link == '') return 'link is required!';
                        }
                        ,
                        success:function(response){
                            if(response.status){
                                then.html(then.find('span').html());
                                updateAlert(response.info,'alert-success','Success!');
                                location.reload();
                            }else {
                                updateAlert(response.info,'alert-danger','Error!');
                            }
                        }
                });

            });

            $('.com-link-panel .editable').editable('toggleDisabled');

         });

    </script>
</block>